package com.huahai.pojo.vo.comment;

import com.baomidou.mybatisplus.annotation.TableField;
import com.huahai.pojo.entity.Comment;
import com.huahai.pojo.vo.user.UserVO;
import lombok.Data;
import org.springframework.beans.BeanUtils;

import java.io.Serializable;
import java.util.Date;

/**
 * 评论封装响应类
 * 
 * @author huahai
 */
@Data
public class CommentVO implements Serializable {
    
    private static final long serialVersionUID = -7362346559822156653L;
    
    /**
     * id
     */
    private Long id;

    /**
     * 评论内容
     */
    private String content;

    /**
     * 评论用户 id
     */
    private Long userId;

    /**
     * 图片 id
     */
    private Long pictureId;

    /**
     * 父级评论 id
     */
    private Long fatherId;

    /**
     * 是否点赞
     */
    @TableField(exist = false)
    private Boolean isLike = false;

    /**
     * 创建时间
     */
    private Date createTime;

    /**
     * 点赞量
     */
    private Long likeCount;

    /**
     * 发表评论的用户信息
     */
    private UserVO user;

    /**
     * 封装类转对象
     *
     * @param commentVO
     * @return  comment
     */
    public static Comment voToObj(CommentVO commentVO) {
        if (commentVO == null) {
            return null;
        }
        Comment comment = new Comment();
        BeanUtils.copyProperties(commentVO, comment);
        return comment;
    }

    /**
     * 对象转封装类
     *
     * @param comment
     * @return commentVO
     */
    public static CommentVO objToVo(Comment comment) {
        if (comment == null) {
            return null;
        }
        CommentVO commentVO = new CommentVO();
        BeanUtils.copyProperties(comment, commentVO);
        return commentVO;
    }
}